package com.hexiang.consumer;

import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.common.filter.FilterContext;
import org.apache.rocketmq.common.filter.MessageFilter;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.ArrayList;
import java.util.List;

public class MyMessageFilter implements MessageFilter {

    @Override
    public boolean match(MessageExt msg, FilterContext context) {
        boolean flag = false;
        List<String> tagList = new ArrayList<>();
        tagList.add("TagA");
        tagList.add("TagB");
        String property = msg.getProperty("a");
        if (StringUtils.isNotBlank(msg.getTags()) && tagList.contains(msg.getTags())) {
            if (StringUtils.isNotBlank(property)) {
                int id = Integer.parseInt(property);
                if (id > 0 && id < 3) {
                    flag = true;
                }
            }
        }
        return flag;
    }
}